package com.example.demo2.controller;

import com.example.demo2.generator.entity.Dpt;
import com.example.demo2.generator.entity.R;
import com.example.demo2.generator.service.DptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Api(value = "DptController",tags = "Dpt测试接口")
@Controller
@RequestMapping("/dpt")
public class DptController {
    @Autowired
    private DptService dptService;
    @ApiOperation(value = "所有部门查询")
    @RequestMapping("/getAllDpt")
    @ResponseBody
    public R getAllDpt(){
        List<Dpt> dpt = dptService.queryAllDpt();
        return R.ok(dpt);
    }
    @ApiOperation(value = "通过部门名字查询")
    @RequestMapping("/queryByName")
    @ResponseBody
    public R queryByName(String dptName){
        List<Dpt>dpt;
        System.out.println(dptName);
        if("-1".equals(dptName)) {
            dpt = dptService.queryAllDpt();
        }
        else {
         dpt = dptService.queryByName(dptName);
        }
        return R.ok(dpt);
    }
    @ApiOperation(value = "添加部门信息")
    @RequestMapping("/addDpt")
    @ResponseBody
    public R addDpt(@RequestBody Dpt dpt) {
        dptService.insert(dpt);

        return R.ok("添加成功");
    }
    @ApiOperation(value = "删除部门信息")
    @RequestMapping("/delDpt")
    @ResponseBody
    public R delDpt(Dpt dpt) {
        dptService.deleteById(dpt);

        return R.ok("删除");
    }
    @ApiOperation(value = "更新部门信息")
    @RequestMapping("/UpdateDpt")
    @ResponseBody
    public R updateDpt(Dpt dpt) {
        dptService.updateDpt(dpt);
        return R.ok("更新完成",dpt);
    }


}
